package com.example.qxfw.ybzz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.qxfw.common.entity.MapPoint;
import com.example.qxfw.common.entity.qx.MsgMediumSmallScale;
import com.example.qxfw.common.entity.xt.ContourSetting;
import com.example.qxfw.common.entity.zy.BaseProduct;
import com.example.qxfw.common.mapper.MsgmediumsmallscaleMapperXml;
import com.example.qxfw.common.util.DateUtil;
import com.example.qxfw.common.util.DmgisUtils;
import com.example.qxfw.dzzh.mapper.DzWarningMapper;
import com.example.qxfw.dzzh.service.YjfxdzYzService;
import com.example.qxfw.mongodb.hy.entity.HyDocFile;
import com.example.qxfw.ybzz.mapper.BaseProductMapper;
import com.example.qxfw.ybzz.mapper.MsgMediumSmallScaleMapper;
import com.example.qxfw.ybzz.service.BaseProductService;
import com.example.qxfw.ybzz.service.MsgMediumSmallScaleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.*;
import org.apache.xmlbeans.XmlCursor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.io.*;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;

import static com.example.qxfw.common.util.DocxUtil.*;
import static com.example.qxfw.common.util.DocxUtil.setCellLocation;

@Slf4j
@Service
public class MsgMediumSmallScaleServiceImpl implements MsgMediumSmallScaleService {
    @Value("${dmgis.ip}")
    private String dmgisIp;

    @Value("${dmgis.port}")
    private String dmgisPort;

    @Value("${dmgis.serName}")
    private String dmgisSerName;

    @Value("${filePath.resourcePath}")
    private String resourcePath;

    @Value("${filePath.active}")
    private String active;

    @Autowired
    private YjfxdzYzService yjfxdzYzService;

    @Autowired
    private DzWarningMapper dzWarningMapper;

    @Autowired
    private BaseProductMapper baseProductMapper;


    @Qualifier("mongoSecondTemplate")
    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private MsgMediumSmallScaleMapper msgMediumSmallScaleMapper;

    @Autowired
    private MsgmediumsmallscaleMapperXml msgmediumsmallscaleMapperXml;
    @Autowired
    private BaseProductService baseProductService;

    @Value("${city}")
    private String city;

    @Override
    public List<MsgMediumSmallScale> listAvgByElement(String element, String observTime1, String observTime2) {
        return msgMediumSmallScaleMapper.selectList(Wrappers.<MsgMediumSmallScale>query()
                .select("StationID", "StationName", "Longitude", "Latitude", "CAST(avg(" + element + ") AS NUMERIC(10, 1)) as " + element, "County")
                .ne(element, "-65535")
                .lambda()
                .like(MsgMediumSmallScale::getCity, city)
                .between(MsgMediumSmallScale::getObservtime, observTime1, observTime2));
    }

    @Override
    public List<MsgMediumSmallScale> getList(String timespan, String param1, String param2, String forecastType) {
        return msgMediumSmallScaleMapper.selectList26(timespan, param1, param2, forecastType);
    }

    @Override
    public List<MsgMediumSmallScale> getList() {
        return msgMediumSmallScaleMapper.selectList(null);
    }

    @Override
    public List<MsgMediumSmallScale> getList18(Timestamp observTime, String stationId) {
        return msgMediumSmallScaleMapper.selectList18(observTime, stationId);
    }

    @Override
    public List<MsgMediumSmallScale> getList19(String time1, String time2, String stationId) {
        return msgMediumSmallScaleMapper.selectList19(Timestamp.valueOf(time1), Timestamp.valueOf(time2), stationId);
    }

    @Override
    public List<MsgMediumSmallScale> getList1(String time1, String time2, String stationId) {
        return msgMediumSmallScaleMapper.selectList1(Timestamp.valueOf(time1), Timestamp.valueOf(time2), stationId);
    }

    @Override
    public List<MsgMediumSmallScale> getList2(String type, String en, String start, String end) {
        return msgMediumSmallScaleMapper.selectList2(type, en, start, end);
    }

    @Override
    public List<MsgMediumSmallScale> getList3(String observTime, String county) {
        return msgMediumSmallScaleMapper.selectList3(observTime, county);
    }

    @Override
    public List<MsgMediumSmallScale> getList4(String observTime, String stationID) {
        return msgMediumSmallScaleMapper.selectList4(observTime, stationID);
    }

    @Override
    public List<MsgMediumSmallScale> getList5(String observTime1, String observTime2, String county) {
        return msgMediumSmallScaleMapper.selectList5(observTime1, observTime2, county);
    }

    @Override
    public List<MsgMediumSmallScale> getList6(String observTime1, String observTime2, String stationId) {
        return msgMediumSmallScaleMapper.selectList6(observTime1, observTime2, stationId);
    }

    @Override
    public List<MsgMediumSmallScale> getList7(String time, String stationId) {
        return msgMediumSmallScaleMapper.selectList7(time, stationId);
    }

    @Override
    public Integer update(MsgMediumSmallScale msgMediumSmallScale) {
        LambdaUpdateWrapper<MsgMediumSmallScale> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(MsgMediumSmallScale::getStationid, msgMediumSmallScale.getStationid())
                .eq(MsgMediumSmallScale::getObservtime, msgMediumSmallScale.getObservtime());
        Integer rows = msgMediumSmallScaleMapper.update(msgMediumSmallScale, updateWrapper);
        return rows;
    }

    @Override
    public List<String> getMaxTemp(String time1, String time2, String stationId) {
        return msgMediumSmallScaleMapper.selectMaxTemp(time1, time2, stationId);
    }

    @Override
    public List<String> getMaxTemp1(String time1, String time2, String stationId) {
        return msgMediumSmallScaleMapper.selectMaxTemp1(time1, time2, stationId);
    }

    @Override
    public List<String> getMaxTemp2(String time, String stationId) {
        return msgMediumSmallScaleMapper.selectMaxTemp2(time, stationId);
    }

    @Override
    public List<String> getRain(String time1, String time2, String stationId) {
        return msgMediumSmallScaleMapper.selectRain(time1, time2, stationId);
    }

    @Override
    public List<String> getRain1(String time1, String time2, String stationId) {
        return msgMediumSmallScaleMapper.selectRain1(time1, time2, stationId);
    }

    @Override
    public List<String> getRain2(String time1, String time2, String stationId) {
        return msgMediumSmallScaleMapper.selectRain2(time1, time2, stationId);
    }

    @Override
    public List<String> getTemp(String time1, String time2, String stationId) {
        return msgMediumSmallScaleMapper.selectTemp(time1, time2, stationId);
    }

    @Override
    public List<String> getWindVelocity(String time1, String time2, String stationId) {
        return msgMediumSmallScaleMapper.selectWindVelocity(time1, time2, stationId);
    }

    @Override
    public List<String> getMaxTemp3(String time, String stationId) {
        return msgMediumSmallScaleMapper.selectMaxTemp3(time, stationId);
    }

    @Override
    public List<String> getMinTemp(String time1, String time2, String stationId) {
        return msgMediumSmallScaleMapper.selectMinTemp(time1, time2, stationId);
    }

    @Override
    public String getMinTemp1(String time, String stationId) {
        return msgMediumSmallScaleMapper.selectMinTemp1(time, stationId);
    }

    @Override
    public List<MsgMediumSmallScale> getMaxWind(String time, String stationId) {
        return msgMediumSmallScaleMapper.selectMaxWind(time, stationId);
    }

    @Override
    public List<MsgMediumSmallScale> getSumValue(String stationId, String time) {
        return msgMediumSmallScaleMapper.selectSumValue(stationId, time);
    }

    @Override
    public List<MsgMediumSmallScale> getList8(String date1, String date2, String dbName) {
        return msgMediumSmallScaleMapper.selectList8(date1, date2, dbName);
    }

    @Override
    public List<MsgMediumSmallScale> getList9(String date1, String date2, String dbName) {
        return msgMediumSmallScaleMapper.selectList9(date1, date2, dbName);
    }

    @Override
    public String getMaxTime() {
        return msgMediumSmallScaleMapper.selectMaxTime();
    }

    @Override
    public List<MsgMediumSmallScale> getList10(String observTime, String city, String staCondition, String sort) {
        return msgMediumSmallScaleMapper.selectList10(observTime, city, staCondition, sort);
    }

    @Override
    public List<MsgMediumSmallScale> getList11(String observTime, String city, String strCitys, String staCondition, String sort) {
        return msgMediumSmallScaleMapper.selectList11(observTime, city, strCitys, staCondition, sort);
    }

    @Override
    public List<MsgMediumSmallScale> getList12(String m_strSelDbName1, String sortColumn, String observTime, String strCitys, String staCondition, String sort) {
        return msgMediumSmallScaleMapper.selectList12(m_strSelDbName1, sortColumn, observTime, strCitys, staCondition, sort);
    }

    @Override
    public List<MsgMediumSmallScale> getList13(String m_strSelDbName1, String sortColumn, String observTime, String staCondition, String sort) {
        return msgMediumSmallScaleMapper.selectList13(m_strSelDbName1, sortColumn, observTime, staCondition, sort);
    }

    @Override
    public List<MsgMediumSmallScale> getList14(String observTime, String strCitys, String staCondition, String sort) {
        return msgMediumSmallScaleMapper.selectList14(observTime, strCitys, staCondition, sort);
    }

    @Override
    public List<MsgMediumSmallScale> getList15(String observTime, String staCondition, String sort) {
        return msgMediumSmallScaleMapper.selectList15(observTime, staCondition, sort);
    }

    @Override
    public List<MsgMediumSmallScale> getList16(String strSelElement, String strSelWindD, String pdtStart, String pdtEnd, String m_strSelDbName, String strWindDElement, String strwhere) {
        return msgMediumSmallScaleMapper.selectList16(strSelElement, strSelWindD, pdtStart, pdtEnd, m_strSelDbName, strWindDElement, strwhere);
    }

    @Override
    public List<MsgMediumSmallScale> getList17(String strSelElement, String pdtStart, String pdtEnd, String m_strSelDbName, String strwhere) {
        return msgMediumSmallScaleMapper.selectList17(strSelElement, pdtStart, pdtEnd, m_strSelDbName, strwhere);
    }

    @Override
    public List<MsgMediumSmallScale> listAvgByDbName(String dbName, Timestamp time1, Timestamp time2) {
        return msgMediumSmallScaleMapper.selectAvg(dbName, city, time1, time2);
    }

    @Override
    public List<MsgMediumSmallScale> listMaxByDbName(String dbName, Timestamp time1, Timestamp time2) {
        return msgMediumSmallScaleMapper.selectMax(dbName, city, time1, time2);
    }

    @Override
    public List<MsgMediumSmallScale> listMinByDbName(String dbName, Timestamp time1, Timestamp time2) {
        return msgMediumSmallScaleMapper.selectMin(dbName, city, time1, time2);
    }

    @Override
    public List<MsgMediumSmallScale> listSumByDbName(String dbName, Timestamp time1, Timestamp time2) {
        return msgMediumSmallScaleMapper.selectSum(dbName, city, time1, time2);
    }

    @Override
    public List<MsgMediumSmallScale> listMaxByDbName1(String dbName, Timestamp time1, Timestamp time2) {
        return msgMediumSmallScaleMapper.selectMax1(dbName, city, time1, time2);
    }

    @Override
    public List<MsgMediumSmallScale> listAvgByDbName1(String dbName, Timestamp time1, Timestamp time2) {
        return msgMediumSmallScaleMapper.selectAvg1(dbName, city, time1, time2);
    }

    @Override
    public List<MsgMediumSmallScale> listSkAvg(String dbName, String time1, String time2, double lon, double lat, double radius, List<List<Double>> pos) {
        List<MsgMediumSmallScale> msgMediumSmallScales;
        if (ObjectUtils.isNotEmpty(radius) && radius != 0) {
            //圆形查询
            msgMediumSmallScales = msgMediumSmallScaleMapper.selectList(Wrappers.<MsgMediumSmallScale>query()
                    .select("StationID", "StationName", "Longitude", "Latitude", "CAST(avg(" + dbName + ") AS NUMERIC(10, 1)) as " + dbName, "County")
                    .ne(dbName, -65535)
                    .apply("( 6371000 * acos ( " +
                            " cos( radians( {1}))" +
                            " * cos( radians( CAST(Latitude as numeric)))" +
                            " * cos( radians( CAST(Longitude as numeric)) - radians( {0}))" +
                            " + sin( radians( {1} ))" +
                            " * sin( radians( CAST(Latitude as numeric)))" +
                            ")) < {2} ", lon, lat, radius)
                    .lambda()
                    .like(MsgMediumSmallScale::getCity, city)
                    .between(StringUtils.isNotBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1), Timestamp.valueOf(time2))
                    .eq(StringUtils.isBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1))
                    .groupBy(MsgMediumSmallScale::getStationid,
                            MsgMediumSmallScale::getStationname,
                            MsgMediumSmallScale::getLongitude,
                            MsgMediumSmallScale::getLatitude,
                            MsgMediumSmallScale::getCounty));

        } else {
            //绘制查询
            msgMediumSmallScales = msgMediumSmallScaleMapper.selectList(Wrappers.<MsgMediumSmallScale>query()
                    .select("StationID", "StationName", "Longitude", "Latitude", "CAST(avg(" + dbName + ") AS NUMERIC(10, 1)) as " + dbName, "County")
                    .ne(dbName, -65535)
                    .lambda()
                    .like(MsgMediumSmallScale::getCity, city)
                    .between(StringUtils.isNotBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1), Timestamp.valueOf(time2))
                    .eq(StringUtils.isBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1))
                    .groupBy(MsgMediumSmallScale::getStationid,
                            MsgMediumSmallScale::getStationname,
                            MsgMediumSmallScale::getLongitude,
                            MsgMediumSmallScale::getLatitude,
                            MsgMediumSmallScale::getCounty));

            Iterator<MsgMediumSmallScale> iterator = msgMediumSmallScales.iterator();
            while (iterator.hasNext()) {
                MsgMediumSmallScale next = iterator.next();
                MapPoint mapPoint = new MapPoint(next.getLongitude(), next.getLatitude());
                if (!DmgisUtils.isScope(mapPoint, pos)) {
                    iterator.remove();
                }
            }
        }

        return msgMediumSmallScales;
    }

    @Override
    public List<MsgMediumSmallScale> listSkMax(String dbName, String time1, String time2, double lon, double lat, double radius, List<List<Double>> pos) {
        List<MsgMediumSmallScale> msgMediumSmallScales;
        if (ObjectUtils.isNotEmpty(radius) && radius != 0) {
            //圆形查询
            msgMediumSmallScales = msgMediumSmallScaleMapper.selectList(Wrappers.<MsgMediumSmallScale>query()
                    .select("StationID", "StationName", "Longitude", "Latitude", "CAST(max(" + dbName + ") AS NUMERIC(10, 1)) as " + dbName, "County")
                    .ne(dbName, -65535)
                    .apply("( 6371000 * acos ( " +
                            " cos( radians( {1}))" +
                            " * cos( radians( CAST(Latitude as numeric)))" +
                            " * cos( radians( CAST(Longitude as numeric)) - radians( {0}))" +
                            " + sin( radians( {1} ))" +
                            " * sin( radians( CAST(Latitude as numeric)))" +
                            ")) < {2} ", lon, lat, radius)
                    .lambda()
                    .like(MsgMediumSmallScale::getCity, city)
                    .between(StringUtils.isNotBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1), Timestamp.valueOf(time2))
                    .eq(StringUtils.isBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1))
                    .groupBy(MsgMediumSmallScale::getStationid,
                            MsgMediumSmallScale::getStationname,
                            MsgMediumSmallScale::getLongitude,
                            MsgMediumSmallScale::getLatitude,
                            MsgMediumSmallScale::getCounty));

        } else {
            //绘制查询
            msgMediumSmallScales = msgMediumSmallScaleMapper.selectList(Wrappers.<MsgMediumSmallScale>query()
                    .select("StationID", "StationName", "Longitude", "Latitude", "CAST(max(" + dbName + ") AS NUMERIC(10, 1)) as " + dbName, "County")
                    .ne(dbName, -65535)
                    .lambda()
                    .like(MsgMediumSmallScale::getCity, city)
                    .between(StringUtils.isNotBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1), Timestamp.valueOf(time2))
                    .eq(StringUtils.isBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1))
                    .groupBy(MsgMediumSmallScale::getStationid,
                            MsgMediumSmallScale::getStationname,
                            MsgMediumSmallScale::getLongitude,
                            MsgMediumSmallScale::getLatitude,
                            MsgMediumSmallScale::getCounty));

            Iterator<MsgMediumSmallScale> iterator = msgMediumSmallScales.iterator();
            while (iterator.hasNext()) {
                MsgMediumSmallScale next = iterator.next();
                MapPoint mapPoint = new MapPoint(next.getLongitude(), next.getLatitude());
                if (!DmgisUtils.isScope(mapPoint, pos)) {
                    iterator.remove();
                }
            }
        }

        return msgMediumSmallScales;
    }

    @Override
    public List<MsgMediumSmallScale> listSkMin(String dbName, String time1, String time2, double lon, double lat, double radius, List<List<Double>> pos) {
        List<MsgMediumSmallScale> msgMediumSmallScales;
        if (ObjectUtils.isNotEmpty(radius) && radius != 0) {
            //圆形查询
            msgMediumSmallScales = msgMediumSmallScaleMapper.selectList(Wrappers.<MsgMediumSmallScale>query()
                    .select("StationID", "StationName", "Longitude", "Latitude", "CAST(min(" + dbName + ") AS NUMERIC(10, 1)) as " + dbName, "County")
                    .ne(dbName, -65535)
                    .apply("( 6371000 * acos ( " +
                            " cos( radians( {1}))" +
                            " * cos( radians( CAST(Latitude as numeric)))" +
                            " * cos( radians( CAST(Longitude as numeric)) - radians( {0}))" +
                            " + sin( radians( {1} ))" +
                            " * sin( radians( CAST(Latitude as numeric)))" +
                            ")) < {2} ", lon, lat, radius)
                    .lambda()
                    .like(MsgMediumSmallScale::getCity, city)
                    .between(StringUtils.isNotBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1), Timestamp.valueOf(time2))
                    .eq(StringUtils.isBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1))
                    .groupBy(MsgMediumSmallScale::getStationid,
                            MsgMediumSmallScale::getStationname,
                            MsgMediumSmallScale::getLongitude,
                            MsgMediumSmallScale::getLatitude,
                            MsgMediumSmallScale::getCounty));

        } else {
            //绘制查询
            msgMediumSmallScales = msgMediumSmallScaleMapper.selectList(Wrappers.<MsgMediumSmallScale>query()
                    .select("StationID", "StationName", "Longitude", "Latitude", "CAST(min(" + dbName + ") AS NUMERIC(10, 1)) as " + dbName, "County")
                    .ne(dbName, -65535)
                    .lambda()
                    .like(MsgMediumSmallScale::getCity, city)
                    .between(StringUtils.isNotBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1), Timestamp.valueOf(time2))
                    .eq(StringUtils.isBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1))
                    .groupBy(MsgMediumSmallScale::getStationid,
                            MsgMediumSmallScale::getStationname,
                            MsgMediumSmallScale::getLongitude,
                            MsgMediumSmallScale::getLatitude,
                            MsgMediumSmallScale::getCounty));

            Iterator<MsgMediumSmallScale> iterator = msgMediumSmallScales.iterator();
            while (iterator.hasNext()) {
                MsgMediumSmallScale next = iterator.next();
                MapPoint mapPoint = new MapPoint(next.getLongitude(), next.getLatitude());
                if (!DmgisUtils.isScope(mapPoint, pos)) {
                    iterator.remove();
                }
            }
        }

        return msgMediumSmallScales;
    }

    @Override
    public List<MsgMediumSmallScale> listSkSum(String dbName, String time1, String time2, double lon, double lat, double radius, List<List<Double>> pos) {
        List<MsgMediumSmallScale> msgMediumSmallScales;
        if (ObjectUtils.isNotEmpty(radius) && radius != 0) {
            //圆形查询
            msgMediumSmallScales = msgMediumSmallScaleMapper.selectList(Wrappers.<MsgMediumSmallScale>query()
                    .select("StationID", "StationName", "Longitude", "Latitude", "CAST(sum(" + dbName + ") AS NUMERIC(10, 1)) as " + dbName, "County")
                    .ne(dbName, -65535)
                    .apply("( 6371000 * acos ( " +
                            " cos( radians( {1}))" +
                            " * cos( radians( CAST(Latitude as numeric)))" +
                            " * cos( radians( CAST(Longitude as numeric)) - radians( {0}))" +
                            " + sin( radians( {1} ))" +
                            " * sin( radians( CAST(Latitude as numeric)))" +
                            ")) < {2} ", lon, lat, radius)
                    .lambda()
                    .like(MsgMediumSmallScale::getCity, city)
                    .between(StringUtils.isNotBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1), Timestamp.valueOf(time2))
                    .eq(StringUtils.isBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1))
                    .groupBy(MsgMediumSmallScale::getStationid,
                            MsgMediumSmallScale::getStationname,
                            MsgMediumSmallScale::getLongitude,
                            MsgMediumSmallScale::getLatitude,
                            MsgMediumSmallScale::getCounty));

        } else {
            //绘制查询
            msgMediumSmallScales = msgMediumSmallScaleMapper.selectList(Wrappers.<MsgMediumSmallScale>query()
                    .select("StationID", "StationName", "Longitude", "Latitude", "CAST(sum(" + dbName + ") AS NUMERIC(10, 1)) as " + dbName, "County")
                    .ne(dbName, -65535)
                    .lambda()
                    .like(MsgMediumSmallScale::getCity, city)
                    .between(StringUtils.isNotBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1), Timestamp.valueOf(time2))
                    .eq(StringUtils.isBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1))
                    .groupBy(MsgMediumSmallScale::getStationid,
                            MsgMediumSmallScale::getStationname,
                            MsgMediumSmallScale::getLongitude,
                            MsgMediumSmallScale::getLatitude,
                            MsgMediumSmallScale::getCounty));

            Iterator<MsgMediumSmallScale> iterator = msgMediumSmallScales.iterator();
            while (iterator.hasNext()) {
                MsgMediumSmallScale next = iterator.next();
                MapPoint mapPoint = new MapPoint(next.getLongitude(), next.getLatitude());
                if (!DmgisUtils.isScope(mapPoint, pos)) {
                    iterator.remove();
                }
            }
        }

        return msgMediumSmallScales;
    }

    @Override
    public List<MsgMediumSmallScale> listSkMax1(String dbName, String time1, String time2, double lon, double lat, double radius, List<List<Double>> pos) {
        List<MsgMediumSmallScale> msgMediumSmallScales;
        if (ObjectUtils.isNotEmpty(radius) && radius != 0) {
            //圆形查询
            msgMediumSmallScales = msgMediumSmallScaleMapper.selectList(Wrappers.<MsgMediumSmallScale>query()
                    .select("StationID", "StationName", "Longitude", "Latitude", "CAST(max(CAST(case when " + dbName + "=-65536 then 0 else " + dbName + " end AS float)) AS NUMERIC(10, 0)) as " + dbName, "County")
                    .ne(dbName, -65535)
                    .apply("( 6371000 * acos ( " +
                            " cos( radians( {1}))" +
                            " * cos( radians( CAST(Latitude as numeric)))" +
                            " * cos( radians( CAST(Longitude as numeric)) - radians( {0}))" +
                            " + sin( radians( {1} ))" +
                            " * sin( radians( CAST(Latitude as numeric)))" +
                            ")) < {2} ", lon, lat, radius)
                    .lambda()
                    .like(MsgMediumSmallScale::getCity, city)
                    .between(StringUtils.isNotBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1), Timestamp.valueOf(time2))
                    .eq(StringUtils.isBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1))
                    .groupBy(MsgMediumSmallScale::getStationid,
                            MsgMediumSmallScale::getStationname,
                            MsgMediumSmallScale::getLongitude,
                            MsgMediumSmallScale::getLatitude,
                            MsgMediumSmallScale::getCounty));

        } else {
            //绘制查询
            msgMediumSmallScales = msgMediumSmallScaleMapper.selectList(Wrappers.<MsgMediumSmallScale>query()
                    .select("StationID", "StationName", "Longitude", "Latitude", "CAST(max(CAST(case when " + "winddirect " + "=-65536 then 0 else 0 end AS float)) AS NUMERIC(10, 0)) as winddirect", "County")
                    .ne("winddirect", -65535)
                    .lambda()
                    .like(MsgMediumSmallScale::getCity, city)
                    .between(StringUtils.isNotBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1), Timestamp.valueOf(time2))
                    .eq(StringUtils.isBlank(time2), MsgMediumSmallScale::getObservtime, Timestamp.valueOf(time1))
                    .groupBy(MsgMediumSmallScale::getStationid,
                            MsgMediumSmallScale::getStationname,
                            MsgMediumSmallScale::getLongitude,
                            MsgMediumSmallScale::getLatitude,
                            MsgMediumSmallScale::getCounty));

            Iterator<MsgMediumSmallScale> iterator = msgMediumSmallScales.iterator();
            while (iterator.hasNext()) {
                MsgMediumSmallScale next = iterator.next();
                MapPoint mapPoint = new MapPoint(next.getLongitude(), next.getLatitude());
                if (!DmgisUtils.isScope(mapPoint, pos)) {
                    iterator.remove();
                }
            }
        }

        return msgMediumSmallScales;
    }

    @Override
    public List<MsgMediumSmallScale> getList26(String observTime1, String observTime2, String stationId, String element) {
        return msgMediumSmallScaleMapper.selectList(Wrappers.<MsgMediumSmallScale>query()
                .select("observtime", element + " as datechar")
                .lambda()
                .between(MsgMediumSmallScale::getObservtime, Timestamp.valueOf(observTime1), Timestamp.valueOf(observTime2))
                .eq(MsgMediumSmallScale::getStationid, stationId)
                .orderByDesc(MsgMediumSmallScale::getStationid, MsgMediumSmallScale::getObservtime));
    }

    @Override
    public List<MsgMediumSmallScale> getSumRain(String obserTime1, String observTime2, String city) {
        return msgMediumSmallScaleMapper.selectSumRain(obserTime1, observTime2, city);
    }

    @Override
    public List<MsgMediumSmallScale> listByParam(String observTime1, String observTime2, String stationId) {
        return msgMediumSmallScaleMapper.selectList(Wrappers.<MsgMediumSmallScale>query()
//                .select( )
                .lambda()
                .between(MsgMediumSmallScale::getObservtime, Timestamp.valueOf(observTime1), Timestamp.valueOf(observTime2))
                .eq(MsgMediumSmallScale::getStationid, stationId)
                .orderByDesc(MsgMediumSmallScale::getStationid, MsgMediumSmallScale::getObservtime));
    }

    @Override
    public MsgMediumSmallScale selectMaxMinTempByParam(String observTime1, String observTime2, String stationId) {
        return msgMediumSmallScaleMapper.selectMaxMinTemp(Timestamp.valueOf(observTime1), Timestamp.valueOf(observTime2), stationId);
    }

    @Override
    public MsgMediumSmallScale selectSumRainByParam(String observTime1, String observTime2, String stationId) {
        return msgMediumSmallScaleMapper.selectSumRain1(Timestamp.valueOf(observTime1), Timestamp.valueOf(observTime2), stationId);
    }

    @Override
    public List<MsgMediumSmallScale> selectStationNameByCounty(String county) {
        return msgMediumSmallScaleMapper.selectStationNameByCounty(county);
    }
    //<------------------------------------------------------------------------------------------------------------------------------>


    @Override
    public List<MsgMediumSmallScale> getDifferentConditionsOfmsgmediumsmallscale(String startTime, String endTime, String condition, String[] area, Integer num) {
        // 处理时间
        Timestamp time1 = DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(startTime));
        Calendar calendar = Calendar.getInstance();
        // 时间取整小时
        if (StringUtils.isBlank(endTime)) {
            calendar.setTime(time1);
            calendar.set(Calendar.MINUTE, 0); // 设置分钟为零
            calendar.set(Calendar.SECOND, 0); // 设置秒数为零
        }
        // 处理查询是国家站还是自动站，0表示不查，1表示查
        // 这里的数组含有两个值，第一个值表示国家站“5”开头的站点编号，第二个值表示自动站非“5”开头的站点编号
        String term = new String();// 用来确定查询值
        if (area[0].equals("0") && area[1].equals("0")) {
            term = "5N";// 随便给的值，查不到就行
        } else if (area[0].equals("1") && area[1].equals("0")) {
            term = "5%";
        } else if (area[1].equals("0") && area[1].equals("1")) {
            term = "N%"; // 匹配非5开头的单个字符
        } else if (area[1].equals("1") && area[1].equals("1")) {
            term = "%";
        }

        List<MsgMediumSmallScale> list = new ArrayList<>();
        // 处理不同条件
        if (condition.equals("雨量") || condition.equals("风速")) {
            // 时间段的雨量和极大风
            if (!endTime.equals("null")) {
                list = msgMediumSmallScaleMapper.selectList(new LambdaQueryWrapper<MsgMediumSmallScale>()
                        .select(
                                MsgMediumSmallScale::getStationid,
                                MsgMediumSmallScale::getStationname,
                                MsgMediumSmallScale::getObservtime,
                                MsgMediumSmallScale::getLongitude,
                                MsgMediumSmallScale::getLatitude,
                                MsgMediumSmallScale::getRain,
                                MsgMediumSmallScale::getWinddirect,
                                MsgMediumSmallScale::getWindvelocity,
                                MsgMediumSmallScale::getCounty)
                        .between(MsgMediumSmallScale::getObservtime,
                                time1,
                                DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(endTime)))
                        .like(MsgMediumSmallScale::getStationid, term)
                        .orderByDesc(MsgMediumSmallScale::getObservtime));
                return list;
            } else {
                // 整点雨量\风速
                Timestamp roundedTime = new Timestamp(calendar.getTimeInMillis());
                list = msgMediumSmallScaleMapper.selectList(new LambdaQueryWrapper<MsgMediumSmallScale>()
                        .select(MsgMediumSmallScale::getStationid, MsgMediumSmallScale::getStationname, MsgMediumSmallScale::getObservtime, MsgMediumSmallScale::getLongitude, MsgMediumSmallScale::getLatitude,
                                MsgMediumSmallScale::getRain, MsgMediumSmallScale::getWinddirect, MsgMediumSmallScale::getWindvelocity, MsgMediumSmallScale::getCounty)
                        .eq(MsgMediumSmallScale::getObservtime, roundedTime)
                        .like(MsgMediumSmallScale::getStationid, term));
                return list;
            }
        } else if (condition.equals("温度") || condition.equals("湿度")) {
            // 时间段的温度湿度最大最小值
            if (!endTime.equals("null")) {
                if (num == 2) {
                    list = msgMediumSmallScaleMapper.selectList(new LambdaQueryWrapper<MsgMediumSmallScale>()
                            .select(MsgMediumSmallScale::getStationid, MsgMediumSmallScale::getStationname, MsgMediumSmallScale::getObservtime, MsgMediumSmallScale::getLongitude, MsgMediumSmallScale::getLatitude,
                                    MsgMediumSmallScale::getDrybulbtemp, MsgMediumSmallScale::getRelhumidity, MsgMediumSmallScale::getCounty)
                            .between(MsgMediumSmallScale::getObservtime, time1, DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(endTime)))
                            .orderByDesc(MsgMediumSmallScale::getDrybulbtemp)// 按照字段降序排序
                            .like(MsgMediumSmallScale::getStationid, term)
                            .last("LIMIT 1"));// 限制查询结果数量为 1
                } else if (num == 1) {
                    list = msgMediumSmallScaleMapper.selectList(new LambdaQueryWrapper<MsgMediumSmallScale>()
                            .select(MsgMediumSmallScale::getStationid, MsgMediumSmallScale::getStationname, MsgMediumSmallScale::getObservtime, MsgMediumSmallScale::getLongitude, MsgMediumSmallScale::getLatitude,
                                    MsgMediumSmallScale::getDrybulbtemp, MsgMediumSmallScale::getRelhumidity, MsgMediumSmallScale::getCounty)
                            .between(MsgMediumSmallScale::getObservtime, time1, DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(endTime)))
                            .orderByAsc(MsgMediumSmallScale::getDrybulbtemp)// 按照字段升序排序
                            .like(MsgMediumSmallScale::getStationid, term)
                            .last("LIMIT 1"));// 限制查询结果数量为 1
                }else {
                    //平均气温
                    List<MsgMediumSmallScale> msgMediumSmallScaleList = msgmediumsmallscaleMapperXml.selectAvgTemp(Timestamp.valueOf(startTime), Timestamp.valueOf(endTime));
                    return msgMediumSmallScaleList;
                }
            } else {
                // 整点温度\湿度
                Timestamp roundedTime = new Timestamp(calendar.getTimeInMillis());
                list = msgMediumSmallScaleMapper.selectList(new LambdaQueryWrapper<MsgMediumSmallScale>()
                        .select(MsgMediumSmallScale::getStationid, MsgMediumSmallScale::getStationname, MsgMediumSmallScale::getObservtime, MsgMediumSmallScale::getLongitude, MsgMediumSmallScale::getLatitude,
                                MsgMediumSmallScale::getDrybulbtemp, MsgMediumSmallScale::getRelhumidity, MsgMediumSmallScale::getCounty)
                        .eq(MsgMediumSmallScale::getObservtime, roundedTime));
            }
        } else if (condition.equals("气压")) {
            // 时间段的平均气压
            if (!endTime.equals("null")) {
                list = msgMediumSmallScaleMapper.getAvgStationPress(time1, DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(endTime)), term);
            } else {
                // 整点气压
                Timestamp roundedTime = new Timestamp(calendar.getTimeInMillis());
                list = msgMediumSmallScaleMapper.selectList(new LambdaQueryWrapper<MsgMediumSmallScale>()
                        .select(MsgMediumSmallScale::getStationid, MsgMediumSmallScale::getStationname, MsgMediumSmallScale::getObservtime, MsgMediumSmallScale::getLongitude, MsgMediumSmallScale::getLatitude,
                                MsgMediumSmallScale::getStationpress, MsgMediumSmallScale::getCounty)
                        .eq(MsgMediumSmallScale::getObservtime, roundedTime));
            }
        }

        return list;
    }

    @Override
    public List<MsgMediumSmallScale> multiFactorSearchRiver(String startTime, String endTime, String station) {
        Timestamp start = DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(startTime));
        Timestamp end;
        System.err.println(endTime);
        if (StringUtils.isBlank(endTime)) {
            end = null;
        }else {
            end = DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(endTime));
        }
        return msgmediumsmallscaleMapperXml.multipleElementQuery(start, end, station);
    }


    @Override
    public List<MsgMediumSmallScale> selectAvgTemp(final Timestamp startTime, final Timestamp endTime) {
        return msgmediumsmallscaleMapperXml.selectAvgTemp(startTime, endTime);
    }

    @Override
    public List<MsgMediumSmallScale> selectMaxTemp(final Timestamp startTime, final Timestamp endTime) {
        return msgmediumsmallscaleMapperXml.selectMaxTemp(startTime, endTime);
    }

    @Override
    public List<MsgMediumSmallScale> selectMinTemp(final Timestamp startTime, final Timestamp endTime) {
        return msgmediumsmallscaleMapperXml.selectMinTemp(startTime, endTime);
    }

    @Override
    public List<MsgMediumSmallScale> selectHourlyTemperature(final Timestamp time) {
        return msgmediumsmallscaleMapperXml.selectHourlyTemperature(time);
    }

    @Override
    public List<MsgMediumSmallScale> selectHourlyWind(final Timestamp time) {
        return msgmediumsmallscaleMapperXml.selectHourlyWind(time);
    }

    @Override
    public List<MsgMediumSmallScale> selectExtremeWinds(final Timestamp startTime, final Timestamp endTime) {
        return msgmediumsmallscaleMapperXml.selectExtremeWinds(startTime, endTime);
    }

    @Override
    public List<MsgMediumSmallScale> selectHourlyHumidity(final Timestamp startTime) {
        return msgmediumsmallscaleMapperXml.selectHourlyHumidity(startTime);
    }

    @Override
    public List<MsgMediumSmallScale> selectMinimumHumidity(final Timestamp startTime, final Timestamp endTime) {
        return msgmediumsmallscaleMapperXml.selectMinimumHumidity(startTime, endTime);
    }

    @Override
    public List<MsgMediumSmallScale> selectHourlyAirPressure(final Timestamp startTime) {
        return msgmediumsmallscaleMapperXml.selectHourlyAirPressure(startTime);
    }

    @Override
    public List<MsgMediumSmallScale> selectAverageAirPressure(final Timestamp startTime, final Timestamp endTime) {
        return msgmediumsmallscaleMapperXml.selectAverageAirPressure(startTime, endTime);
    }

    @Override
    public List<MsgMediumSmallScale> selectHourlyRain(final Timestamp startTime) {
        return msgmediumsmallscaleMapperXml.selectHourlyRain(startTime);
    }

    @Override
    public List<MsgMediumSmallScale> selectCumulativeRainfall(final Timestamp startTime, final Timestamp endTime) {
        return msgmediumsmallscaleMapperXml.selectCumulativeRainfall(startTime, endTime);
    }

    @Override
    public List<MsgMediumSmallScale> selectStatisticalChartOfAgriculturalStationElements(final String stationName, final Timestamp startTime, final Timestamp endTime, final String column) {
        return msgmediumsmallscaleMapperXml.selectStatisticalChartOfAgriculturalStationElements(stationName, column, startTime, endTime);
    }

    @Override
    public List<ContourSetting> getContourSetting(String type) {
        return msgmediumsmallscaleMapperXml.getContourSetting(type);
    }

    @Override
    public  Float selectAvgRain(Timestamp startTime, Timestamp endTime) {
       return msgmediumsmallscaleMapperXml.selectAvgRain(startTime, endTime);
    }

    @Override
    public  Float selectMaxRain(Timestamp startTime, Timestamp endTime) {
        return msgmediumsmallscaleMapperXml.selectMaxRain(startTime, endTime);
    }
    @Override
    public String selectMaxStation(Timestamp startTime, Timestamp endTime) {
        return msgmediumsmallscaleMapperXml.selectMaxStation(startTime, endTime);
    }

    @Override
    public Object createProduct(int year, String startTime, String endTime, String userName, String productName, String productType, Date parse) {
        //模板路径
        String templatePath;
        //产品路径
        String targetPath;
        //获取应用程序的主目录位置
        ApplicationHome applicationHome = new ApplicationHome(this.getClass());
        if (active.equals("dev")) {
            templatePath = applicationHome.getDir().getParentFile().getParentFile().getAbsolutePath() +
                    "\\src\\main\\resources\\templates\\yjfwTemp\\雨情快报模板.docx";
            targetPath = applicationHome.getDir().getParentFile().getParentFile().getAbsolutePath() +
                    "\\src\\main\\resources\\temp\\雨情快报.docx";
        } else {
            templatePath = applicationHome.getSource().getParentFile() +
                    "\\resource\\templates\\yjfwTemp\\雨情快报模板.docx";
            targetPath = applicationHome.getSource().getParentFile() +
                    "\\resources\\temp\\雨情快报.docx";
        }

        try (
                //读取文件内容
                FileInputStream templateStream = new FileInputStream(templatePath);
//                InputStream templateStream = new ClassPathResource(templatePath).getInputStream();
                //创建新的文档
                XWPFDocument document = new XWPFDocument(templateStream);
                //输出文件
                FileOutputStream targetSteam = new FileOutputStream(targetPath);
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
            //段落替换
            String[] placeholders = new String[]{"[0]", "[1]", "[2]", "[3]", "[4]","[5]"};
            //替换内容
            String start =  startTime.substring(5, 7) + "月" + startTime.substring(8, 10) + "日"+startTime.substring(11, 13)+"时";
            String end=  endTime.substring(5, 7) + "月" + endTime.substring(8, 10) + "日"+endTime.substring(11, 13)+"时";
            String date1 =start+ "至"+end;
           String type ="";
            //String sta = "那付";
            Timestamp timestamp1 = DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(startTime));
            Timestamp timestamp2 = DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(endTime));
            Float avg = msgmediumsmallscaleMapperXml.selectAvgRain(timestamp1, timestamp2);
            Float max = msgmediumsmallscaleMapperXml.selectMaxRain(timestamp1, timestamp2);
            String sta = msgmediumsmallscaleMapperXml.selectMaxStation(timestamp1, timestamp2);
            List<MsgMediumSmallScale> msgMediumSmallScales = msgmediumsmallscaleMapperXml.selectCumulativeRainfall(timestamp1, timestamp2);
            if (avg >= 0 && avg < 1) {
                type ="小雨";
            } else if (avg >= 1 && avg < 10) {
                type ="中雨";
            } else if (avg >= 10 && avg < 25) {
                type ="大雨";
            } else if (avg >= 25 && avg < 50) {
                type = "暴雨";
            } else if (avg >= 50 && avg < 100) {
                type ="大暴雨";
            } else if (avg >= 100 && avg < 250) {
                type = "特大暴雨";
            } else {
                type ="极端暴雨"; // 超过250的情况
            }
            List<Map> stationInfo = new ArrayList<>();
            for (MsgMediumSmallScale msgMediumSmallScale : msgMediumSmallScales) {
                Map map = new HashMap<>();
                map.put("stationname",msgMediumSmallScale.getStationname());
                map.put("rain",msgMediumSmallScale.getRain());
                stationInfo.add(map);
            }
            String[] replacements = new String[]{String.valueOf(year), date1, type, String.valueOf(avg), String.valueOf(max),sta};

            //提取文档中的段落列表
            List<XWPFParagraph> paragraphs = document.getParagraphs();
            // 替换段落内容
            for (int i = 0; i < paragraphs.size(); i++) {
                XWPFParagraph paragraph = paragraphs.get(i);
                //获取段落内容
                String text = paragraph.getText();

                //替换文字内容
                replaceTextInParagraph(paragraph, placeholders, replacements);

                //插入雨情实况表格
                if ( text.equals("[雨情实况]")) {
                    //获取下标
                    XmlCursor cursor = paragraph.getCTP().newCursor();
                    XWPFTable table = document.insertNewTbl(cursor);//插入表格
                    // 添加表头
                    XWPFTableRow headerRow = table.getRow(0);
                    headerRow.getCell(0).setText("站名 1");
                    headerRow.addNewTableCell().setText("雨量 1");
                    headerRow.addNewTableCell().setText("站名 2");
                    headerRow.addNewTableCell().setText("雨量 2");
                    headerRow.addNewTableCell().setText("站名 3");
                    headerRow.addNewTableCell().setText("雨量 3");

                    int count = 0; // 记录当前行的站点数
                    XWPFTableRow dataRow = table.createRow(); // 创建第一行

                    for (Map<String, Object> date : stationInfo) {
                        // 每三个站点创建新行
                        if (count % 3 == 0 && count != 0) {
                            dataRow = table.createRow();
                        }

                        int cellIndex = (count % 3) * 2; // 每行有六个单元格 (站名1, 雨量1, 站名2, 雨量2, 站名3, 雨量3)

                        // 设置站名和雨量
                        if (cellIndex < 6) {
                            dataRow.getCell(cellIndex).setText(date.get("stationname").toString());
                            dataRow.getCell(cellIndex + 1).setText(date.get("rain").toString());
                        }

                        count++;
                    }

                    // 确保每行都有三个站点数据，填充剩余空白单元格
                    while (count % 3 != 0) {
                        int cellIndex = (count % 3) * 2;
                        dataRow.getCell(cellIndex).setText(""); // 填充空白站名
                        dataRow.getCell(cellIndex + 1).setText(""); // 填充空白雨量
                        count++;
                    }

                    // 设置表格位置和单元格对齐方式（假设 setTableLocation 和 setCellLocation 方法存在）
                    setTableLocation(table, "center");
                    setCellLocation(table, "CENTER", "center");

                    // 移除原始的段落（假设 document 和 paragraph 已经定义并适用）
                    document.removeBodyElement(document.getPosOfParagraph(paragraph));
                }
              
            }
            // 将生成的文档保存到输出文件
            document.write(targetSteam);
            log.info("文档生成成功");
            targetSteam.close();

            // 设置前端响应
            byte[] buffer = new byte[1024];
            int bytesRead;
            //从生成得文档中读取数据
            FileInputStream inputStream = new FileInputStream(targetPath);

            while ((bytesRead = inputStream.read(buffer)) != -1) {
                byteArrayOutputStream.write(buffer, 0, bytesRead);
            }
            byte[] byteArray = byteArrayOutputStream.toByteArray();
            //查询是否入库

           SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH");
          String productName1 = sdf.format(parse) + productName+ productType;
            // String maxId = emergencyMapper.getMaxId();
            // Emergency emergency = new Emergency();
            // emergency.setId(Integer.valueOf(maxId));
            // emergency.setDocpath(productName);
            // emergencyMapper.updateById(emergency);
            List<BaseProduct> list2 = baseProductService.getList2(productName1, "雨情快报");
            if (list2.size() != 0) {
                //pg已入库，存入mongo库
                HyDocFile hyDocFile = new HyDocFile();
                hyDocFile.setData(byteArray);
                hyDocFile.setTable_name("base_product");
                hyDocFile.setId(String.valueOf(list2.get(0)));
                mongoTemplate.save(hyDocFile);
            } else {
                //先存入pg库
                BaseProduct baseProduct = new BaseProduct();

                baseProduct.setForecasttime(new Date());
                baseProduct.setMaketime(new Date());
                baseProduct.setMaker(userName);
                //baseProduct.setContext(cityName + sdf.format(date) + "发布最新应急产品：" + title);
                baseProduct.setProductname(productName1);
                baseProduct.setProducttype("雨情快报");
                baseProductService.save(baseProduct);
                //存入mongo库
                HyDocFile hyDocFile = new HyDocFile();
                hyDocFile.setData(byteArray);
                hyDocFile.setTable_name("base_product");
                hyDocFile.setId(String.valueOf(baseProduct.getId()));
                mongoTemplate.save(hyDocFile);
            }
            HttpHeaders headers = new HttpHeaders();
            headers.setContentDispositionFormData("attachment", productName1 + "雨情快报.docx");
            headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
            headers.setContentLength(byteArray.length);
//            wordToPdf(targetPath,targetPdfPath);
            return new ResponseEntity<>(byteArray, headers, HttpStatus.OK);

        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("文档生成失败");
        }
        return null;
    }


}
